<template>
  <el-dialog
    @close="jdysshCancel('jdysshRuleForm')"
    :close-on-click-modal="false"
    title="节点验收审核"
    :visible.sync="jdysshVisible"
    width="600px"
  >
    <div class="scroll-view">
      <el-descriptions :column="1" border>
        <template v-for="(item, index) in jdysArrData.nodes">
          <el-descriptions-item :label="item.name" :key="index">
            <template v-if="item.file.length">
              <div class="flex ac fw">
                <div
                  @click="$fileViewHandle(fileItem)"
                  class="file-name"
                  v-for="(fileItem, fileIndex) in item.file"
                  :key="fileIndex"
                >
                  {{ fileItem.file_name }}
                </div>
              </div>
            </template>
            <span v-else>{{ item.content }}</span>
          </el-descriptions-item>
          <el-descriptions-item v-if="jdysArrData.remark" label="备注" :key="index">
            <span>{{ jdysArrData.remark }}</span>
          </el-descriptions-item>
        </template>
      </el-descriptions>
      <el-form
        :model="jdysshRuleForm"
        :rules="jdysshRules"
        ref="jdysshRuleForm"
        label-position="top"
      >
        <el-form-item label="" prop="reviewPassed">
          <el-radio-group v-model="jdysshRuleForm.reviewPassed" size="small">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            :rows="4"
            class="input-box"
            v-model="jdysshRuleForm.remark"
            type="textarea"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer">
      <el-button
        type="primary"
        @click="jdysshSubmit('jdysshRuleForm')"
        :disabled="diaLoading"
        :loading="diaLoading"
        >提交</el-button
      >
      <el-button @click="jdysshCancel('jdysshRuleForm')">关闭</el-button>
    </span>
  </el-dialog>
</template>
<script>
import projectApi from "@/api/projectApi";
import companyApi from "@/api/companyApi";
import adminApi from "@/api/adminApi";
import { getUserInfo } from "@/utils/auth";
import foremanApi from "@/api/foremanApi";

export default {
  name: "",
  props: {
    addDialogVisible: {
      type: Boolean,
      default: false,
      required: false,
    },
    project_id: {
      required: false,
    },
    projectNodesItem: {
      required: false,
    },
    jdysArrData: {
      required: false,
    },
  },
  data() {
    return {
      jdysshVisible: false,
      jdysshRuleForm: {
        remark: "",
        reviewPassed: 1,
      },
      jdysshRules: {},
      diaLoading: false,
    };
  },
  watch: {
    addDialogVisible(val1, val2) {
      console.log(this.jdysArrData, "jdysArrData");
      this.jdysshVisible = this.addDialogVisible;
    },
  },
  computed: {},
  mounted() {},
  methods: {
    // 节点验收审核
    jdysshCancel(formName) {
      this.jdysshRuleForm = {
        remark: "",
        reviewPassed: 1,
      };
      this.$nextTick(() => {
        this.$refs[formName].clearValidate();
        this.$emit("onClose", true);
      });
    },
    jdysshSubmit(formName) {
      let jdysshRuleForm = this.jdysshRuleForm;
      console.log(jdysshRuleForm, "节点验收审核参数");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.diaLoading = true;
          // 通过
          if (jdysshRuleForm.reviewPassed == 1) {
            projectApi
              .nodeAcceptancePassed({
                project_id: this.project_id,
                node_id: this.projectNodesItem.id,
                remark: jdysshRuleForm.remark,
              })
              .then((res) => {
                console.log(res, "节点验收审核");
                this.diaLoading = false;
                if (res.code == 200) {
                  this.$emit("onSuccess", true);
                }
                this.$message({
                  type: res.code == 200 ? "success" : "warning",
                  message: res.code == 200 ? "处理成功" : res.message,
                });
              })
              .catch((err) => {
                this.diaLoading = false;
                this.$message({
                  type: "warning",
                  message: err.message,
                });
              });
            return;
          }
          // 拒绝
          projectApi
            .nodeAcceptanceRejected({
              project_id: this.project_id,
              node_id: this.projectNodesItem.id,
              remark: jdysshRuleForm.remark,
            })
            .then((res) => {
              console.log(res, "节点验收审核");
              this.diaLoading = false;
              if (res.code == 200) {
                this.$emit("onSuccess", true);
              }

              this.$message({
                type: res.code == 200 ? "success" : "warning",
                message: res.code == 200 ? "处理成功" : res.message,
              });
            })
            .catch((err) => {
              this.diaLoading = false;
              this.$message({
                type: "warning",
                message: err.message,
              });
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "./index.scss";
</style>